﻿using System;
using System.Collections.Generic;

using System.Text;

namespace Estimate.Common.DBFieldTypes
{
    /// <summary>
    /// 给定sendpoint或者sendpoint的组合，根据sendpoint和clock的映射关系，得出相应的clock,sendpoint的数组
    /// </summary>
    public class SendpointToClock
    {
        /// <summary>
        /// 存放 clock 与 sendpoint 对应关系数组
        /// </summary>
        private static Dictionary<ForeSendpointType, ForeClockType> _compareData;

        static SendpointToClock()
        {
            //初始化 clock sendpoint 对照表
            _compareData = new Dictionary<ForeSendpointType,ForeClockType>();
            {
                _compareData[ForeSendpointType.H05] = ForeClockType.H08;
                _compareData[ForeSendpointType.H06] = ForeClockType.H08;
                _compareData[ForeSendpointType.H10] = ForeClockType.H08;
                _compareData[ForeSendpointType.H08] = ForeClockType.H08;
                _compareData[ForeSendpointType.H15] = ForeClockType.H20;
                _compareData[ForeSendpointType.H16] = ForeClockType.H20;
            };

        }


        /// <summary>
        ///  给定sendpoint或者sendpoint的组合，根据sendpoint和clock的映射关系，得出相应的clock数组
        /// </summary>
        /// <param name="sendpoint">sendpoint或者sendpoint的组合</param>
        /// <param name="clocks">得出的clock数组</param>
        /// <param name="sendpoints">得出的sendpoint数组</param>
        public void GetClockArraySendpointArrayWithSendPoint(ForeSendpointType sendpoint,out ForeClockType[] clocks, out ForeSendpointType[] sendpoints)
        {

            List<ForeClockType> clockSet = new List<ForeClockType>();
            List<ForeSendpointType> sendpointSet = new List<ForeSendpointType>();

            string[] names = Enum.GetNames(typeof(ForeSendpointType));
            foreach (string name in names)
            {
                ForeSendpointType singleSendpoint = (ForeSendpointType)Enum.Parse(typeof(ForeSendpointType), name);
                if ((sendpoint & singleSendpoint) == singleSendpoint)
                {
                    if (!clockSet.Contains(_compareData[singleSendpoint]))
                        clockSet.Add(_compareData[singleSendpoint]);
                    sendpointSet.Add(singleSendpoint);
                }
            }

            clocks = clockSet.ToArray();
            sendpoints = sendpointSet.ToArray();
        }

        /// <summary>
        /// 给定sendpoint数组，给出对应的clock数组
        /// </summary>
        /// <param name="sendpoints">发报时刻数组</param>
        /// <returns>起报时刻数组</returns>
        public ForeClockType[] GetClockArrayWithSendPointArray(ForeSendpointType[] sendpoints)
        {
            List<ForeClockType> clockSet = new List<ForeClockType>();

            foreach (ForeSendpointType sendpoint in sendpoints)
            {
                if (!clockSet.Contains(_compareData[sendpoint]))
                    clockSet.Add(_compareData[sendpoint]);
            }

            return clockSet.ToArray();
        }
    
    }

   
}
